<?php
//命名空间 (文件路径)
namespace src\Check;
//引入自动加载类文件
require_once __DIR__ . '/../../autoload.php';
//引入数据库类
use  src\DataBase;
class UserInfoCheck
{
    public $username = '';
    public $password = '';
    public $checkResult = false;

    public function __construct($username, $password)
    {
        $this->username = $username;
        $this->password = $password;
    }

    public function checkCookie()
    {
        if (isset($_COOKIE['school']['username']) && $_COOKIE['school']['password']) {
            if (($_COOKIE['school']['username'] == ($this->username)) && ($_COOKIE['school']['password'] == ($this->password))) {
                return $this->checkResult = true;
            }
        } else {
            return $this->checkResult = false;
        }
    }

    public function check()
    {
        if ($this->checkCookie() == true) {
            return $this->checkResult = true;
        } else {
            //数据库查询
            $db = new DataBase\DataBaseOperate('139.196.124.180', 'school', 'user1', 'Mcx857264', 'utf8');
            $selectResult = $db->select('studentInfo', '*', array('studentNumber' => $this->username, 'password' => $this->password));
            if (isset($selectResult)) {
                return $this->checkResult = true;
            } else {
                return $this->checkResult = false;
            }
        }
    }

    public function index()
    {
        echo "用户信息检查类加载成功";
    }
}

?>